package com.jcl.recruit.api.channel.controller;

import com.jcl.core.resp.ApiResponse;
import com.jcl.recruit.channel.model.ChannelNet;
import com.jcl.recruit.channel.service.ChannelNetService;
import com.jcl.recruit.core.constants.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ChannelController
 * @Description TODO
 * @Author yyliu
 * @Date 2018/9/11 16:26
 * @Version 1.0
 **/
@RequestMapping("/api/channel")
@RestController
public class ChannelController {

    @Autowired
    private ChannelNetService channelNetService;

    @RequestMapping("/list")
    public ApiResponse listChannel(){
        List<ChannelNet> list = channelNetService.selectList();
        return ApiResponse.success(list);
    }

    @RequestMapping("/get/{id}")
    public ApiResponse findOne(@PathVariable("id") String id){
        ChannelNet channelNet = channelNetService.findOne(Integer.parseInt(id));
        return ApiResponse.success(channelNet);
    }

    @RequestMapping("/add")
    public ApiResponse addChannel(@RequestBody ChannelNet channelNet){
        channelNetService.addChannelNet(channelNet);
        return ApiResponse.success(channelNet);
    }

    @RequestMapping("/update")
    public ApiResponse updateChannel(@RequestBody ChannelNet channelNet){
        channelNetService.updateChannelNet(channelNet);
        return ApiResponse.success(Constants.ReturnInfo.SUCCESS_MSG);
    }

    @RequestMapping("/delete/{id}")
    public ApiResponse delChannel(@PathVariable("id") String id){
        channelNetService.deleteChannelNet(Integer.parseInt(id));
        return ApiResponse.success(Constants.ReturnInfo.SUCCESS_MSG);
    }


}
